<!-- INCLUDE top.html -->
  <link type="text/css" href="_skins/tplcss/index.css" rel="stylesheet"/>
   <script src="http://ditu.google.cn/maps?file=api&amp;v=2&amp;key=ABQIAAAAWlfiFVYKHX8tCx74bFRnfhSiHqGNQq5LUfoyer1zi8GUzfLY3hRNqVpl6-
Mmsn4Hn7s2-IudYC-RHw&sensor=false" type="text/javascript"></script>
  <script type="text/javascript">
	/**
 @description 地图功能 
 @author ffpan
 @requires  googlemap api  (http://ditu.google.cn/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAWlfiFVYKHX8tCx74bFRnfhRpp30BDXp-1xIerK7XpUs0bSzu7xSVrUD63jB2YX5cVd1HtH12nrekzg&hl=zh-CN)
 @version 1.0
*/

MyGoogleMap = function(){
	this.initialize();
}

MyGoogleMap.prototype = {
	
	/** 初始化地图 **/
	initialize : function(){
		/**初始化参数 **/
		this.mapDiv = document.getElementById("map_canvas");

		if (GBrowserIsCompatible()) {
			this.map = new GMap2(this.mapDiv);
			this.map.setCenter(new GLatLng(31.979, 120.894), 13);
			this.geocoder = new GClientGeocoder();
		}
	},
	
	
	/** 根据地名返回经纬度 **/
	getPointer : function(address){
		var  _this = this;
		if (this.geocoder) {
			this.geocoder.getLatLng( address , function(point) {
				if(!point){point="unknown";}
				_this.postData(point , address);
		});
      }
	},
	
	/** 将对应的名称和经纬度提交到后台页面 **/
	postData : function(point , address){
		var prefix="江苏省南通市";
		var data = {
			pname : address.replace(prefix , ""),
			pLat : point.y,
			pLng : point.x
		}
		var url = "admin_latlng_send.php";
		$.get(url , data, function(txt){
			document.title = (txt);
		}); 
	}
}


$(document).ready(function(){
	var newMap = new MyGoogleMap();
	/*var mapInfo = [
		["朝晖花园" , 49],
		["万象东园" , 123],
		["梅花小苑" , 56],
		["名都广场" , 29]
	];
	
	$.each(mapInfo, function(index) { 
		var address=mapInfo[index][0];
		var number = mapInfo[index][1];
		newMap.getPointer(address , number);
	});*/

	$("#updatemap").bind("click" , function(){
		var url = "admin_latlng_get.php";
		$.get(url , "" , function(json){
			json = eval(json);
			$.each(json, function(k){
				var pid = json[k]["id"];
				var plaza =  json[k]["name"];
				var prefix="江苏省南通市";
				newMap.getPointer(prefix+plaza ,plaza);
			});
		})
	});
}); 


window.unload = function(){
	GUnload();
}
  </script>

<body>
<div  id="map_canvas" style="width:250px;height:130px;"></div>
<input type="button" value="更新地图数据" id="updatemap" />
</body>
</html>